package com.ruoyi.project.er.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.er.domain.PaeaErError;
import com.ruoyi.project.er.service.IPaeaErErrorRegisterService;
import com.ruoyi.project.er.service.IPaeaErErrorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.project.er.service.IPaeaErPointService;

import java.sql.Date;
import java.util.Arrays;
import java.util.List;

/**
 * 督办创建Controller
 *
 * @author XQ.XU
 * @date 2020-03-20
 */
@Controller
@RequestMapping("/er/paeaErErrorRegister")
public class PaeaErErrorRegisterController extends BaseController
{
    private String prefix = "er/paeaErErrorRegister";
    @Autowired
    private IPaeaErErrorRegisterService paeaErErrorRegisterService;
    @Autowired
    private IPaeaErErrorService paeaErErrorService;
    @Autowired
    private IPaeaErPointService paeaErPointService;
    @RequiresPermissions("er:paeaErErrorRegister:view")
    @GetMapping()
    public String paeaErError()
    {
        return prefix + "/paeaErErrorRegister";
    }

    /**
     * 查询督办查询列表
     */
    @RequiresPermissions("er:paeaErErrorRegister:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaErError paeaErError)
    {
        startPage();
        List<PaeaErError> list = paeaErErrorService.list(new QueryWrapper<>(paeaErError));
        return getDataTable(list);
    }

    /**
     * 删除督办查询
     */
    @RequiresPermissions("er:paeaErErrorRegister:remove")
    @Log(title = "督办查询", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaErErrorRegisterService.deletePaeaErError(Arrays.asList(ids.split(","))));
    }
    /**
     * 新增督办查询
     */
   // @GetMapping("/registerErrorPre/{errSource}")
    @GetMapping("/registerErrorPre")
    public String registerErrorPre(PaeaErError paeaErError,ModelMap mmap)
    {

        //TODO 修改整改日期
        paeaErError.setCorrectLimitDate(new Date(System.currentTimeMillis()));
        mmap.put("paeaErError",paeaErError);
        if(StringUtils.isEmpty(paeaErError.getTradeId())&& StringUtils.isEmpty(paeaErError.getVchNo())){
            return prefix + "/registerErrorWithOutTrade";
        }
        return prefix + "/registerErrorWithTrade";
    }

    /**
     * 新增保存督办查询
     */
    @RequiresPermissions("er:paeaErErrorRegister:registerError")
    @Log(title = "督办查询", businessType = BusinessType.INSERT)
    @PostMapping("/registerError")
    @ResponseBody
    public AjaxResult registerError(PaeaErError paeaErError )
    {
        return toAjax(paeaErErrorRegisterService.registerError(paeaErError));
    }






    /**
     * 修改督办查询
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaErError paeaErError = paeaErErrorService.getById(id);
        mmap.put("paeaErError", paeaErError);
        return prefix + "/edit";
    }

    /**
     * 修改保存督办查询
     */
    @RequiresPermissions("er:paeaErErrorRegister:edit")
    @Log(title = "督办查询", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaErError paeaErError)
    {
        return toAjax(paeaErErrorService.saveOrUpdate(paeaErError));
    }


}
